package com.company.cloud.mall.modules.data.mapper;

import java.time.LocalDateTime;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.company.cloud.mall.modules.data.models.OrderStatusDataModel;

public interface ShopOrderStatisticMapper {

	
	
	
	/**
	 * 订单状态数据统计
	 * */
	@Select("select status AS status, sum(fund) AS fund ,count(1) AS num "
			+ "from mall_order_info  ${ew.customSqlSegment}")
	public List<OrderStatusDataModel> orderStatus(@Param(Constants.WRAPPER) Wrapper<OrderStatusDataModel> queryWrapper);
	
	
	/**
	 * 根据日期分组订单状态数据统计
	 * */
	@Select("select date_format(order_date,'${format}') AS d, status AS status, sum(fund) AS fund ,"
			+ "count(1) AS num from mall_order_info where "
			+ " order_date>=#{startDt,jdbcType=TIMESTAMP} "
			+ "and order_date<=#{endDt,jdbcType=TIMESTAMP} "
			+ "group by status,date_format(order_date,'${format}') ")
	public List<OrderStatusDataModel> orderStatusByDate(
			
			 @Param("startDt") LocalDateTime startDt
			 ,@Param("endDt") LocalDateTime endDt
			 ,@Param("format") String format
	);
	
	
	
	/**
	 * 退款统计
	 * */
	@Select("select state AS status,count(1) AS num,sum(fund) AS fund "
			+ "from mall_order_refunds  ${ew.customSqlSegment}")
	public List<OrderStatusDataModel> refundStatus(@Param(Constants.WRAPPER) Wrapper<OrderStatusDataModel> queryWrapper);
	
	
	
	/**
	 * 退款退货统计
	 * */
	@Select("select state AS status,count(1) AS num,sum(fund) AS fund "
			+ "from mall_order_returns ${ew.customSqlSegment}")
	public List<OrderStatusDataModel> returnsStatus(@Param(Constants.WRAPPER) Wrapper<OrderStatusDataModel> queryWrapper);
	

	
	
	
}
